package tree.递归;

import po.TreeNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 平衡二叉树110.java
 * @Description TODO https://leetcode-cn.com/problems/balanced-binary-tree/
 * @createTime 2021年04月01日 13:01:00
 */
public class 平衡二叉树110 {

    public boolean isBalanced(TreeNode root) {
        if (root==null){
            return true;
        }
        return Math.abs(countDeep(root.left)-countDeep(root.right))<=1 && isBalanced(root.left) && isBalanced(root.right);
    }

    private int countDeep(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(countDeep(root.left),countDeep(root.right))+1;
    }
}
